EvaUnit = {}
EvaUnit.Scopes = {}

function EvaUnit:Begin(name)
	local scope = {}
	setmetatable(scope, {__index = _G})
	setfenv(2, scope)
	self.Scopes[name] = scope
end

function EvaUnit:Run(name)
	local scope = self.Scopes[name]
	local t = {}
	for name, func in pairs(scope) do
		table.insert(t, name)
	end

	table.sort(t)

	for _, name in ipairs(t) do
		if (xpcall(scope[name], self.ErrorHandler)) then
			DEFAULT_CHAT_FRAME:AddMessage(name..": OK!")
		end
	end
end

EvaUnit.ErrorHandler = function (msg)
	local stack = debugstack(2)
	DEFAULT_CHAT_FRAME:AddMessage(msg)
	DEFAULT_CHAT_FRAME:AddMessage(stack)
end

EvaUnit:Begin("a")

function Test1()
	print("test1")
end

function Test2()
	print("test2")
end

EvaUnit:Run("a")

EvaUnit:Begin("b")

function Test3()
	print("test3")
end


function Test4()
	print("test4")
end

EvaUnit:Run("b")

